//
//  BKTwoCollectionView.m
//  FastBee
//
//  Created by mac on 16/9/11.
//  Copyright © 2016年 xbk. All rights reserved.
//

#import "BKTwoCollectionView.h"
#import "BKTwoCollectionFlowLayout.h"
#import "BKTwoCollectionViewCell.h"
#import "bktwocollectionModel.h"

@interface BKTwoCollectionView()<UICollectionViewDataSource>

@end

static NSString *ID = @"ID";

@interface BKTwoCollectionView()

@property (nonatomic,strong) NSArray *dataArr;

@end

@implementation BKTwoCollectionView

- (instancetype)initWithFrame:(CGRect)frame{
    
    BKTwoCollectionFlowLayout *flowLayout = [[BKTwoCollectionFlowLayout alloc]init];

    self = [super initWithFrame:CGRectZero collectionViewLayout:flowLayout];
    
    [self registerClass:[BKTwoCollectionViewCell class] forCellWithReuseIdentifier:ID];
    
    self.dataSource = self;
    
    [self downloadTwoCollectionModel];

    
    return self;
}

//请求网络数据
- (void)downloadTwoCollectionModel{

    [BKTwoCollectionModel downloadDataWithUrl:@"firstSell.json.php" successBlock:^(NSArray *arr) {
        
        //NSLog(@"%@",arr);
        self.dataArr = arr;
        [self reloadData];
        
    } failBlock:^(NSError *error) {
        
        NSLog(@"%@",error);
    }];
}

#pragma mark - UICollectionViewDataSource
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section{

    return self.dataArr.count;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath{

    
    BKTwoCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:ID forIndexPath:indexPath];
    cell.backgroundColor = [UIColor whiteColor];
    
    cell.model = self.dataArr[indexPath.item];
    
    return cell;
}

@end
